/* 爬虫运行总程序 */
export default()=>{
    if (!global.CreepCpu) global.CreepCpu = {}
    for (var RoomName in global.CreepCpu)
    {
        global.CreepCpu[RoomName] = 0
    }
    /* pc */
    for (var pc in Game.powerCreeps)
    {
        if (Game.powerCreeps[pc].ticksToLive)
        {
            Game.powerCreeps[pc].ManageMisson()
        }
    }
    /* c */
    for (var c in Game.creeps)
    {   
        if (!Game.creeps[c].memory.role)
        {
            var InshardMemory = JSON.parse(InterShardMemory.getLocal()) || {}
            if (InshardMemory.creep && InshardMemory.creep[c])
            {
                Game.creeps[c].memory = InshardMemory.creep[c].MemoryData
            }
            continue
        }
        var creep = Game.creeps[c]
        if (creep.spawning)
        {
            creep.room.visual.text(`${creep.memory.role}`,creep.pos.x,creep.pos.y,{color: '#f173ac', font:0.4,align:'center'})
        }
        if (creep.memory.shard && creep.memory.shard != Game.shard.name)
        {
            /* 跨shard的creep运行 */
            creep.ManageMisson()
            continue
        }
        /* 正常本shard运行 */
        var role = creep.memory.role
        var belong = creep.memory.belong
        if (!global.CreepNumData) continue
        if (!global.CreepNumData[belong]) continue
        var startCreepCpu = Game.cpu.getUsed()
        if (!global.CreepNumData[belong][role]) continue
        var fun = global.CreepNumData[belong][role].fun
        if (fun)
        {
            /* 执行固定函数 */
            fun(creep)
        }
        else
        {
            /* 执行任务 */
            creep.ManageMisson()
        }
        var endCreepCpu = Game.cpu.getUsed()
        global.CreepCpu[creep.memory.belong] += (endCreepCpu - startCreepCpu)
    }
}